<?php
	require_once("../conexion/conexion.php");
	$fecha = date("d/m/Y");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />

<script src="../include_js/jquery.js" type="text/javascript"></script>
<style>
#Normal
{
border:1px solid #D3E4E5;
}
#texto
{
	font-family:Verdana, Arial, Helvetica, sans-serif; 
	color:#0066CC; 
}
.asterisco
{
	color:#0000FF;
	font-weight:bold;
}
</style>
<script>
var cont1=2;
function puntitos(donde,caracter)
{
	pat = /[\*,\+,\(,\),\?,\,$,\[,\],\^]/;
	valor = donde.value;
	largo = valor.length;
	crtr = true;
	if(isNaN(caracter) || pat.test(caracter) == true)
	{
		if (pat.test(caracter)==true)
		{ 
			caracter = "\"" + caracter;
		}
		carcter = new RegExp(caracter,"g");
		valor = valor.replace(carcter,"");
		donde.value = valor;
		crtr = false;
	}
	else
	{
		var nums = new Array();
		cont = 0;
		for(m=0;m<largo;m++)
		{
			if(valor.charAt(m) == "." || valor.charAt(m) == " ")
				{continue;}
			else
			{
				nums[cont] = valor.charAt(m);
				cont++;
			}
		}
	}
	var cad1="",cad2="",tres=0;
	if(largo > 3 && crtr == true)
	{
		for (k=nums.length-1;k>=0;k--)
		{
			cad1 = nums[k];
			cad2 = cad1 + cad2;
			tres++;
			if((tres%3) == 0)
			{
				if(k!=0)
				{
					cad2 = "." + cad2;
				}
			}
		}
		donde.value = cad2;
	}
}

function validar(e)
{ 
    tecla = (document.all) ? e.keyCode : e.which; 
    if (tecla==8) return true; //Tecla de retroceso (para poder borrar) 
    patron = /\d/; //ver nota 
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
} 

function EliminarFila(fila)
{
	var Tr = fila;
	while(Tr.nodeName.toLowerCase()!='tr')
	{
		Tr=Tr.parentNode;
	}
	
	var root = Tr.parentNode;
	root.removeChild(Tr);
}

function AgregaFila()
{	
	//alert(cont1);
	nuevaFila = document.getElementById("producto").insertRow(-1);
	nuevaFila.id=cont1;
	nuevaFila.className="Normal";
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"' class=\"Normal\"><input id='txtCantidad"+cont1+"' type='text' name='txtCantidad"+cont1+"' size='28' /></td>";
	
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input id='txtEspecificacion"+cont1+"' type='text' name='txtEspecificacion"+cont1+"' size='28' /></td>";
	
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input id='txtUnitario"+cont1+"' type='text' name='txtUnitario"+cont1+"' size='28'/></td>";
	
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input id='txtTotal"+cont1+"' type='text' name='txtTotal"+cont1+"' size='28'/></td>";
	
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input type='button' value='[x]' onclick='EliminarFila(this);'></td>";

	//document.getElementById("txtCantidad").value = cont1;
	cont1++;	
}
</script>
</head>

<body>
<form name="form_cheque" id="form_cheque" method="post">
<?php
	$factura = $_POST['factura'];
	$doc = $_POST['doc'];
	$rut = $_POST['rut'];
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="uno">
  <tr>
    <td id="Normal" colspan="4"><hr /></td>
  </tr>
  <tr>
    <td id="Normal" colspan="4">&nbsp;&nbsp;<label id="texto">Fecha de Hoy:</label><label style="color:#0000FF; font-size:11px; font-weight:bold"><?php echo $fecha;?></label><div id="datos" style="float:right; clear:none; vertical-align:top; margin-right:10px; margin-top:-15px;"><label style="color:#0000FF; font-size:12px; font-weight:bold;">Datos Obligatorios(*)</label></div></td>
  </tr>
  <tr>
    <td colspan="4" id="Normal" style="padding-bottom:10px; padding-left:0px; padding-top:6px; padding-right:0px;">&nbsp;&nbsp;<label id="texto" style="color:#0000FF; font-weight:bold;">DOCUMENTO BOLETA</label></td>
  </tr>
  <tr>
    <td id="Normal" width="13%">&nbsp;&nbsp;<label id="texto">N&deg; Boleta</label></td>
    <td id="Normal" width="27%"><input type="text" name="txtBoleta" onkeypress="return validar(event)" />&nbsp;<label class="asterisco">*</label></td>
    <td id="Normal" width="7%"><label id="texto">Fecha</label></td>
    <td id="Normal" width="53%"><select name="cmb_Dia" id="cmb_Dia">
      <option value="0">Dia</option>
      <option value="01">1</option>
      <option value="02">2</option>
      <option value="03">3</option>
      <option value="04">4</option>
      <option value="05">5</option>
      <option value="06">6</option>
      <option value="07">7</option>
      <option value="08">8</option>
      <option value="09">9</option>
      <option value="10">10</option>
      <option value="11">11</option>
      <option value="12">12</option>
      <option value="13">13</option>
      <option value="14">14</option>
      <option value="15">15</option>
      <option value="16">16</option>
      <option value="17">17</option>
      <option value="18">18</option>
      <option value="19">19</option>
      <option value="20">20</option>
      <option value="21">21</option>
      <option value="22">22</option>
      <option value="23">23</option>
      <option value="24">24</option>
      <option value="25">25</option>
      <option value="26">26</option>
      <option value="27">27</option>
      <option value="28">28</option>
      <option value="29">29</option>
      <option value="30">30</option>
      <option value="31">31</option>
    </select>
      <select name="cmb_Mes">
        <option value="0">Mes</option>
        <option value="01">Enero</option>
        <option value="02">Febrero</option>
        <option value="03">Marzo</option>
        <option value="04">Abril</option>
        <option value="05">Mayo</option>
        <option value="06">Junio</option>
        <option value="07">Julio</option>
        <option value="08">Agosto</option>
        <option value="09">Septiembre</option>
        <option value="10">Octubre</option>
        <option value="11">Noviembre</option>
        <option value="12">Diciembre</option>
      </select>
      <select name="cmb_Agno">
        <option value="0">A&ntilde;o</option>
        <option value="2009">2009</option>
        <option value="2010">2010</option>
        <option value="2011">2011</option>
        <option value="2012">2012</option>
        <option value="2013">2013</option>
      </select>&nbsp;<label class="asterisco">*</label></td>
    </tr>
  
  <tr>
    <td id="Normal" colspan="4"><hr /></td>
    </tr>
  <tr>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal"><div id="agrega" style="float:right; margin-right:10px;"><a href="javascript:AgregaFila();">Agrega Nuevo Item</a></div></td>
    </tr>
  <tr>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
  </tr>
  <tr>
    <td id="Normal" colspan="4">
		<table border="0" cellpadding="0" cellspacing="0" width="100%" id="producto">
		<thead>
		<tr>
			<th id="Normal">Cantidad</th>
			<th id="Normal">Especificaci&oacute;n</th>
			<th id="Normal">V.Unitario</th>
			<th id="Normal">Total</th>
			<th id="Normal">&nbsp;</th>
		</tr>
		</thead>
		<tr>
			<td id="Normal" align="center"><input name="txtCantidad1" type="text" size="28" onkeypress="return validar(event)"/></td>
			<td id="Normal" align="center"><input name="txtEspecificacion1" type="text" size="28" /></td>
			<td id="Normal" align="center"><input name="txtUnitario1" type="text" size="28" /></td>
			<td id="Normal" align="center"><input name="txtTotal1" type="text" size="28" /></td>
			<td id="Normal">&nbsp;</td>
		</tr>
		</table>	</td>
    </tr>
  <tr>
    <td id="Normal" colspan="4"><hr /></td>
    </tr>
  
  <tr>
    <td id="Normal">&nbsp;&nbsp;<label id="texto">Total</label></td>
    <td id="Normal"><input type="text" name="txtTotal" />&nbsp;<label class="asterisco">*</label></td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
  </tr>
  <tr>
    <td id="Normal">&nbsp;</td>
    <td id="Normal"><div id="mensaje"></div></td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
    </tr>
  <tr>
    <td id="Normal" colspan="4"><hr /></td>
  </tr>
  <tr>
    <td id="Normal">&nbsp;</td>
    <td id="Normal"><input type="button" name="btn_Guardar" id="btn_Guardar" value="Guardar" /></td>
    <td id="Normal">&nbsp;</td>
    <td id="Normal">&nbsp;</td>
    </tr>
  <tr>
  <td id="Normal">&nbsp;</td>
  <td id="Normal">&nbsp;</td>
  <td id="Normal">&nbsp;</td>
  <td id="Normal">&nbsp;</td>
  </tr>
</table>
</form>
</body>
<script>
$('#btn_Guardar').click(function() 
{ 
        $.ajax({
            type: 'POST',
            url: 'Contabilidad/Ingresa_Cheque.php',
            data: $('#form_cheque').serialize(),
            success: function(data) {
                $('#mensaje').html(data);
            }
        })
});
</script>
</html>
